const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ejs = require("ejs");
const fs = require("fs");

const template = fs.readFileSync(path.resolve(__dirname, "../public/index.ejs"), "utf-8");

const data = {
	title: "Welcome to My Website",
	message: "Hello, EJS!",
	info: JSON.stringify({
		enable: true,
		entry: "data",
		header: "",
		hideOverviewSections: false,
		isBceHeaderVisible: true,
		sidebar: { op: "omit", value: [] },
	}),
};

const html = ejs.render(template, data);

module.exports = {
	entry: "./src/index.js",
	output: {
		publicPath: "/",
		path: path.resolve(__dirname, "../dist"), // 生产模式需要输出
	},
	plugins: [
		new HtmlWebpackPlugin({
			filename: "index.html",
			templateContent: html,
		}),
	],
	devtool: "source-map",
	devServer: {
		host: "localhost", // 启动服务器域名
		port: "3000", // 启动服务器端口号
		open: true, // 是否自动打开浏览器
	},
	mode: "production",
};
